// Show and hide menu
$(document).ready(function () {

  'use strict'

  $(window).scroll(function () {
    'use strict'

    if ($(window).scrollTop() < 80) {

      $('.navbar-default').css({
        'margin-top': '-100px',
        'opacity': '0',
        'background-color': 'rgba(59, 59, 59, 0)'
      })

    } else {

      $('.navbar-default').css({
        'margin-top': '0px',
        'opacity': '1',
        'background-color': 'rgba(59, 59, 59, 0.8)',
        'border-color': '#444'
      })

      $('.navbar-brand img').css({
        'height': '35px',
        'padding-top': '0px'
      })

      $('.navbar-nav > li > a').css({
        'padding-top': '15px'
      })

    }

  })

  // Smooth Scrolling
  // https://css-tricks.com/snippets/jquery/smooth-scrolling/#comment-1078891
  $(function () {
    $('.nav-item, #scroll-to-top').click(function () {
      if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
        if (target.length) {
          $('html,body').animate({
            scrollTop: target.offset().top
          }, 1000);
          return false;
        }
      }
    });
  });



  // active menu item on click
  $('.navbar-nav li a').click(function () {
    'use strict'

    $('.navbar-nav li a').parent().removeClass('active')

    $(this).parent().addClass('active')

  })

  // highlight menu item on scroll
  $(window).scroll(function () {
    'use strict'

    $('section').each(function () {
      'use strict'
      var bb = $(this).attr('id')
      var hei = $(this).outerHeight()
      var grttop = $(this).offset().top - 70

      if ($(window).scrollTop() > grttop && $(window).scrollTop() < grttop + hei) {

        $(".navbar-nav li a[href='#" + bb + "']").parent().addClass("active")

      } else {
        $(".navbar-nav li a[href='#" + bb + "']").parent().removeClass("active")
      }


    })

  })

  // add auto padding to header
  setInterval(function () {
    var windowHeight = $(window).height()
    var containerHeight = $('.header-container').height()
    var padTop = windowHeight - containerHeight

    $('.header-container').css({
      'padding-top': Math.round(padTop / 2) + 'px',
      'padding-bottom': Math.round(padTop / 2) + 'px'
    }, 10)
  })

  // slider
  $('.bx-slider').bxSlider({
    slideWidth: 292.5,
    auto: true,
    minSlides: 1,
    maxSlides: 3,
    slideMargin: 50
  });

  // https://github.com/bfintal/Counter-Up
  $('.counter-num').counterUp({
    delay: 20,
    time: 1300
  });

  // activate WOW.js 
  new WOW().init()



})



